package turtle.system.invest.evaluate;

import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

import org.osite.xml.XmlConstructor;
import org.osite.xml.XmlParam;

import turtle.system.invest.Environment;
import turtle.system.invest.rule.InvestRunnable;

public class OpenFile implements InvestRunnable {

	private String id;
	private String path;
	
	@XmlConstructor
	public OpenFile(
			@XmlParam("id") String id, 
			@XmlParam("path") String path) {
		this.id = id;
		this.path = path;
	}
	
	@Override
	public void run(Environment environment) {
		
		try {
			PrintWriter writer = new PrintWriter(new FileWriter(path));
			environment.set(id, writer);
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}
}
